<%-- 
    Document   : profilecomp
    Created on : 24 déc. 2011, 19:21:58
    Author     : MiniK
--%>


<%@page import="fr.annuaireComp.clientUtils.*"%>
<%@page import="java.util.Stack"%>
<%@page import="java.util.HashSet"%>
<%@page import="fr.PERSOclient.models.ProfileCompModel"%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<% ProfileCompModel profilecompdata = (ProfileCompModel) request.getAttribute("profilecompdata");%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="jquery.treeview.css" />

        <script type="text/javascript" src="jquery-1.7.1.min.js" ></script>
        <script type="text/javascript" src="jquery.treeview.js" ></script>
        <script type="text/javascript" src="jquery.editinplace.js"></script>


        <title>Parcourir les compétences</title>

        <script type="text/javascript" >
            $(document).ready(function(){
             
                $(".cp_annees").editInPlace({	
                    url: "profilecomp?action=edit&attribute=anneesxp",
                    value_required: "true",
                    field_type: "select",
                    select_options: "<%for (int i = 0; i <= 70; ++i) {
                            out.print(i + ",");
                        }%>"
                                });
                                $(".cp_commentaire").editInPlace({	
                                    url: "profilecomp?action=edit&attribute=commentaire",
                                    // value_required: "true",
                                    field_type: "textarea"
		
                                });
                                $(".deletebtn").click(function(event){
                                    var me =   $(this).parent("div");
                                    var url = $(this).attr("href");
                                    //   alert(url);
                                    $.post(url, function(){
                                        //   alert("fuck");
                                        me.slideUp();
                                        me.remove(); 
                                    }).error(function() { alert("Une erreur est survenue lors de la supression."); });
                    
                                    event.preventDefault(); 
                                });
                
                                $("#comptree").treeview({
                                    comptree: "slow"
                                });
                
                                $("li .competence a").click(function(event){
                                    displayCompetence($(this).attr("id"));
                                    event.preventDefault();
                                });
                
                            });
            
                            function displayCompetence(compId)
                            {
                                $.get("profilecomp",{action : "compinfos", id : compId}, function(data){
                                    $("#compinfo").html(data);
                                });
                            }
    
        </script>
    </head>
    <body>
        <h1>Parcourir les compétences</h1>
        <% if (request.getAttribute("infomsg") != null) {%> 
        <div class="info"> <%= request.getAttribute("infomsg")%></div>
        <% }%>

        <% if (request.getAttribute("errormsg") != null) {%> 
        <div class="error"> <%= request.getAttribute("errormsg")%></div>
        <% }%>

        <table>
            <tr>
                <td>
                    <div >
                        <h2>Arbre à compétences</h2>
                        <ul id="comptree">

                            <% String currentSavoir = "", currentDomaine = "";
                                for (CompetenceModel c : profilecompdata.competenceTree) {
                                    if (currentSavoir.length() > 0) {
                                        if (!c.savoir.id.equals(currentSavoir)) {
                                            out.println("</li>");
                                        }
                                    }
                                    if (currentDomaine.length() > 0) {
                                        if (!c.domaine.id.equals(currentDomaine)) {
                                            out.println("</ul></li></ul>");
                                        }
                                    }

                                    if (!c.savoir.id.equals(currentSavoir)) {
                                        out.println(" <li class=\"closed savoir\">");
                                        out.println(c.savoir.libelle);
                                        out.println("<ul>");

                                    }
                                    if (!c.domaine.id.equals(currentDomaine)) {
                                        out.println("<li class=\"domaine\">");

                                        out.println(c.domaine.libelle);
                                        out.println("<ul>");
                                    }

                                    printNodes(c, out);


                                    currentDomaine = c.domaine.id;
                                    currentSavoir = c.savoir.id;
                                }
                            %>
                        </ul></li></ul></li>
                        </ul>
                    </div>
                </td>
                <td>
                    <div id="compinfo">

                    </div>
                </td>
            </tr>
        </table>

        <div id="mycomp">
            <h2>Mes competences</h2>
            <div>
                <% for (CompetencePersonnelModel cp : profilecompdata.userCompetences) {%>
                <div class="comppers" >
                    <h3><%= cp.competence.libelle%></h3>
                    Id Compétence : <%= cp.competence.id%>
                    <br/>
                    Années d'expérience : <span id="<%=cp.competence.id%>" class="cp_annees"> <%= cp.anneesXp%></span>
                    <br/>
                    Commentaires : <span id="<%=cp.competence.id%>" class="cp_commentaire"> <%= (cp.commentaires == null || cp.commentaires.isEmpty()) ? "**aucun**" : cp.commentaires%></span>
                    <br/>

                    <a class="deletebtn" href="profilecomp?action=delete&id=<%= cp.competence.id%>">Supprimer</a>
                </div>
                <% }%>
            </div>
        </div>
    </body>
</html>
<%!
    public void printNodes(CompetenceModel c, JspWriter out) {
        try {
            out.println("<li class=\"competence\">");

            //    out.println(c.id + " : " + c.libelle);
            out.println("<a id=\"" + c.id + "\" href=\"#\">" + c.id + " : " + c.libelle + "</a>");

            if (c.competenceFilles.size() > 0) {
                out.println("<ul>");
                for (CompetenceModel nc : c.competenceFilles) {
                    printNodes(nc, out);
                }
                out.println("</ul>");
            }
            out.println("</li>");
        } catch (Exception ex) {
        }
    }

%>